package app.com.business.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException;


import app.com.business.bo.AffectationGeneralDepartement;
import app.com.business.dao.AffectationGeneralDepartementDao;
import app.com.business.exceptions.MaterielException;

import com.groupeA.dao.impl.GenericDaoImpl;

public class AffectationGeneralDepartementDaoImpl extends GenericDaoImpl<AffectationGeneralDepartement, Long> implements AffectationGeneralDepartementDao{

	public AffectationGeneralDepartementDaoImpl() {
		super(AffectationGeneralDepartement.class);
		// TODO Auto-generated constructor stub
	}
    
	public Long findId(AffectationGeneralDepartement affectationGeneral) {
		System.out.println(affectationGeneral.toString()+"    "+affectationGeneral.getIdAffectationGeneral());
		List affectations = getHibernateTemplate().find("from AffectationGeneralDepartement where IDAFFECTATIONGENERAL = 1 "); //and SALLE = ? and PROF = ?",affectationGeneral.getCodeAffectation(),affectationGeneral.getSalle().getIdSalle(),affectationGeneral.getProf().getIdProf()) ;
		AffectationGeneralDepartement affectation = new AffectationGeneralDepartement();
		Long id = Long.valueOf(-1) ;
			affectation = (AffectationGeneralDepartement)affectations.get(0);
		
		
			id = affectation.getIdAffectationGeneral();
		
		return id ;
	}

	public AffectationGeneralDepartement getIdAffectation(
			AffectationGeneralDepartement affectationGeneral) throws MaterielException{
		try {
			List affectations = getHibernateTemplate().find("from AffectationGeneralDepartement where CODEAFFECTATION = ? and SALLE = ? and PROF = ?",affectationGeneral.getCodeAffectation(),affectationGeneral.getSalle().getIdSalle(),affectationGeneral.getProf().getIdProf()) ;
			if(affectations == null | affectations.size()==0 | affectations.get(0)==null)
			{
				throw new MaterielException();
			}
			return (AffectationGeneralDepartement)affectations.get(0);
		} catch (HibernateObjectRetrievalFailureException ex) {
			new MaterielDaoImpl();
		}
		return null ;
	}
	

}
